package com.yonyou.brigade.third_parties.yihao.controller;

import com.alibaba.fastjson.JSONObject;
import com.yonyou.brigade.util.operateutil.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/10/23.
 */
@Controller
@RequestMapping("/yihao")
public class Test {

    @Autowired
    private RedisUtils redisUtils;

    @RequestMapping(value = "/getRedis1",method = RequestMethod.POST)
    public @ResponseBody
    Map<String, String> testUcUser(@RequestBody JSONObject body){
        Map<String,String> result = new HashMap<>();

        redisUtils.setKey("access_token_clyh_test","a27c047a-9efc-43a6-a0ce-c95f3feb437a",90);
        System.out.println("redis返回值："+redisUtils.getValue("access_token_clyh_test"));

        System.out.println("key是否存在："+redisUtils.hasKey("access_token_clyh_test"));

        System.out.println("key有效时间："+redisUtils.getExpire("access_token_clyh_test"));

        redisUtils.delKey("access_token_clyh_test");

        System.out.println("key是否存在："+redisUtils.hasKey("access_token_clyh_test"));

        redisUtils.setKey("access_token_clyh_test","a27c047a-9efc-43a6-a0ce-c95f3feb437a",90);

        result.put("result","成功");
        return result;
    }

    @RequestMapping(value = "/getRedis2",method = RequestMethod.POST)
    public @ResponseBody
    Map<String, String> testRedis(@RequestBody JSONObject body){
        Map<String,String> result = new HashMap<>();

        System.out.println("redis返回值："+redisUtils.getValue("access_token_clyh_test"));

        System.out.println("key是否存在："+redisUtils.hasKey("access_token_clyh_test"));

        System.out.println("key有效时间："+redisUtils.getExpire("access_token_clyh_test"));

        result.put("result","成功");
        return result;
    }
}